﻿<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/UserMaster.master" Inherits="System.Web.Mvc.ViewPage<Eacademy.Domain.Models.QuizListViewModel>" %>

<asp:Content ID="Content3" ContentPlaceHolderID="ScriptContent" runat="server">
    <script type="text/javascript">
        $(document).ready(function () {
            var mentorid = 0;
            var href = "";
            $(".subject a").click(function () {
                $(this).siblings(".mentors").slideToggle();
                return false;
            });
            $(".delete-quiz-link").live("click", function (event) {
                event.preventDefault();
                var $link = $(this);
                $("#dialog-confirm").dialog({
                    resizable: false,
                    height: 120,
                    modal: true,
                    draggable: false,
                    buttons: {
                        "Continue": function () {
                            $(this).dialog("close");
                            $.post($link.attr("href"), null, reloadPage);
                        },
                        Cancel: function () {
                            $(this).dialog("close");
                        }
                    }
                });
            })

            $("#add-quiz").live("click", function (event) {
                event.preventDefault();
                var $link = $(this);
                $("#dialog-add-quiz").dialog({
                    resizable: false,
                    height: 250,
                    width: 500,
                    modal: true,
                    position: 'fixed',
                    draggable: false,
                    buttons: {
                        "Continue": function () {
                            $(this).dialog("close");
                            //$.post($link.attr("href"), null, reloadPage)
                            $("#dialog-add-quiz form").submit();
                        },
                        Cancel: function () {
                            $(this).dialog("close");
                        }
                    }
                });
            });
        });

        function reloadPage() { location.reload(true); }
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Subjects
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">
    <h3>
        Quizzes for
        <%=Model.SubjectName %> - <a href="/mentor/subjects" class="back">Back to List</a></h3>
    <input type="button" value="Add Quiz" id="add-quiz" class="button-style" />
    <br />
    <br />
    <%=Html.Grid(Model.QuizViewModelList).Columns(column =>
      {
          column.For(x => x.Description).Sortable(true);
          column.For(x => x.TotalItems).Sortable(true);
          column.For(x => Html.ActionLink("Edit", "Edit", new { id = x.QuizId, mentoruserid = Model.MentorUserId }));
          column.For(x => Html.ActionLink("Delete", "Delete", new { id = x.QuizId, mentorId = Model.MentorId }, new { @class = "delete-quiz-link" }));
          column.For(x => Html.ActionLink("View Questions", "Index", new { Controller = "Questions", id = x.QuizId,subjectid = Model.SubjectId, mentoruserid = Model.MentorUserId }));
      }).Sort(Model.GridSortOptions)
            .Attributes(@id => "grid-style" , cellspacing => "0",cellpadding => "0")
            .Empty("No quizzes")%>
    <div class="event-paging">
        <div class="pager">
            <% if (Model.QuizViewModelList.TotalItemCount > Model.QuizViewModelList.PageSize)
               {%>
            <%= Html.Pager(Model.QuizViewModelList.PageSize, Model.QuizViewModelList.PageNumber, Model.QuizViewModelList.TotalItemCount)%>
            <%} %>
        </div>
    </div>
    <div id="dialog-confirm" title="Delete Quiz" style="display: none;">
    <p>Do you really want to delete this quiz?</p>
    </div>
    <div id="dialog-add-quiz" title="Add Quiz" style="display: none;">
        <form method="post" action="/mentor/quizzes/add/<%=Model.SubjectId %>" autocomplete="off">
        <input type="hidden" name="MentorUserId" value="<%=Model.MentorUserId %>" />
        <table>
            <tr>
                <td class="label">
                    <label for="description">
                        Description
                    </label>
                </td>
                <td class="field" colspan="5">
                    <input type="text" name="Description" style="width: 315px;" />
                </td>
            </tr>
            <tr>
                <td class="label">
                    <label for="timelimit">
                        Time Limit
                    </label>
                </td>
                <td class="field">
                    <input type="text" name="TimeLimit" /> Minutes
                </td>
            </tr>
            <tr>
                <td class="label">
                    <label for="totalitems">
                        Total Items
                    </label>
                </td>
                <td class="field">
                    <input type="text" name="TotalItems" />
                </td>
            </tr>
            <tr>
                <td class="label">
                    <label for="passingscore">
                        Passing Score
                    </label>
                </td>
                <td class="field">
                    <input type="text" name="PassingScore" />
                </td>
            </tr>
        </table>
        </form>
    </div>
</asp:Content>
